package cst.a211myx.startprojecta;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a211myx.startprojecta.bean.WeatherInfo;
import cst.a211myx.startprojecta.listner.WeatherListener;
import cst.a211myx.startprojecta.model.Weather51Model;
import cst.a211myx.startprojecta.model.WeatherModel;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,WeatherListener {
    private EditText cityid;
    private TextView city,temp,ws,wd;
    private Button button;
    private Button button2;

    void init(){
        cityid=(EditText)findViewById(R.id.cityid);
        city=(TextView)findViewById(R.id.city);
        temp=(TextView)findViewById(R.id.temp);
        button=(Button)findViewById(R.id.button);
        button2=(Button)findViewById(R.id.button2);
        ws=(TextView)findViewById(R.id.WS);
        wd=(TextView)findViewById(R.id.WD);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        button.setOnClickListener(this);
        button2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button:
                WeatherModel weatherModel=new WeatherModel();
                weatherModel.getWeather(cityid.getText().toString(),this);
                break;
            case R.id.button2:
                Weather51Model weather51Model=new Weather51Model();
                weather51Model.getWeather(cityid.getText().toString(),this);
                break;
            default:
                break;
        }
    }

    @Override
    public void onResponse(WeatherInfo w) {
        if (w != null) {
            city.setText(w.getCity().toString());
            temp.setText(w.getTemp().toString());
            ws.setText(w.getWS().toString());
            wd.setText(w.getWD().toString());
        }
    }
    @Override
    public void onFail (String msg) {
        System.out.println(msg);

    }
}